package com.nacos.nacosconsumer.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @author Administrator
 */
@Controller
@RequestMapping("/consumer/")
public class ConsumerController {

    @Autowired
    public RestTemplate restTemplate;

    @Autowired
    public LoadBalancerClient loadBalancerClient;

    public String test(String name){

        ServiceInstance serviceInstance =loadBalancerClient.choose("nacos-producer");
        URI uri=serviceInstance.getUri();
        return restTemplate.getForObject(uri+"/producer/pro?name="+name,String.class);
    }
}
